package com.wokeMy.view.html;

import android.app.Dialog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.example.woke.MainActivity;
import com.wokeMy.view.util.Util;
import com.zhongcai.online.R;

public class HxiangZfHtmlActivity extends AppCompatActivity {
    WebView mWebView;
    private String url, urlname;
    private Intent intent;
    //	public static String TEST_IMAGE;
    //	private static final String FILE_NAME = "/ic_icon2.jpg";
    private ClipData myClip;
    private ClipboardManager myClipboard;

    private Handler handler;
            StringBuilder sb = new StringBuilder();
    Dialog dialog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hxiang_zf_html);
        dialog= Util.createLoadingDialog(this);
        // 获取程序中的WebView组件
        mWebView = (WebView) findViewById(R.id.webView1_hxzfHtml_wv);
        findViewById(R.id.back_hxzfHtml_iv).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(HxiangZfHtmlActivity.this,
                        MainActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
                finish();
            }
        });

        url=getIntent().getStringExtra("hxzfHtml");
        url=url.replace("\n","");
        Log.e("hxzfHtml",url);
        initData();
    }
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        //判断是否可以返回操作
        if (mWebView.canGoBack() && event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
            mWebView.goBack();

        } else {
            mWebView.destroy();
            finish();
        }
        return true;

    }

    protected void initData() {
        WebSettings settings = mWebView.getSettings();
        settings.setJavaScriptEnabled(true);// 设置可以运行JS脚本
        settings.setDefaultTextEncodingName("UTF-8");
        settings.setSupportZoom(true);
        settings.setUseWideViewPort(true);
        settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        settings.setLoadWithOverviewMode(true);
        //		mWebView.getBackground().setAlpha(50); // 设置填充透明度 范围：0-255
        //		settings.setSupportZoom(false);// 用于设置webview放大
        //		settings.setBuiltInZoomControls(false);
        settings.setDomStorageEnabled(true);
        //		settings.setTextSize (TextSize.NORMAL);
        ////		settings.setPluginState(PluginState.ON);
        settings.setDatabaseEnabled(true);
        mWebView.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
//        initUrl();
        Util.closeDialog(dialog);
        mWebView.loadDataWithBaseURL("about:blank",url, "text/html", "utf-8", null);
    }
    private void initUrl() {
        url = "<html>\n" +
                " <head>\n" +
                "  <meta http-equiv=\"\\&quot;Content-Type\\&quot;\" content=\"\\&quot;text\\/html;\" charset=\"UTF-8\\&quot;\\/\" />\n" +
                " </head>\n" +
                " <body>\n" +
                "  &lt;\\/head&gt;\n" +
                "  <form id=\"\\&quot;pay_form\\&quot;\" action=\"\\&quot;https:\\/\\/api.mypays.cn\\/api\\/page\\/shortcutpay\\/yibao\\/payApply\\&quot;\" method=\"\\&quot;post\\&quot;\" accept-charset=\"\\&quot;UTF-8\\&quot;\">\n" +
                "   <input type=\"\\&quot;hidden\\&quot;\" name=\"\\&quot;pageContent\\&quot;\" id=\"\\&quot;pageContent\\&quot;\" value=\"\\&quot;https:\\/\\/shouyin.yeepay.com\\/nc-cashier-wap\\/wap\\/request\\/10015843908\\/oueq88WsuipJ9xjspm0Q7A%3D%3D\\&quot;\\/\" />&lt;\\/form&gt;&lt;\\/body&gt;\n" +
                "   <script type=\"\\&quot;text\\/javascript\\&quot;\">document.all.pay_form.submit();<\\/script><\\/html></script>\n" +
                "  </form>\n" +
                " </body>\n" +
                "</html>".replace("\n", "");
    }
}
